/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package vn.ac.c0910g.assignment.DAO;

import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import vn.ac.c0910g.assignment.Entity.Administrator;
import vn.ac.c0910g.assignment.Entity.AdministratorFacade;

/**
 *
 * @author BachLe
 */
public class AdministratorDAO {
    AdministratorFacade administratorFacade = lookupAdministratorFacadeBean();

    public AdministratorDAO(){

    }

    private AdministratorFacade lookupAdministratorFacadeBean() {
        try {
            Context c = new InitialContext();
            return (AdministratorFacade) c.lookup("java:global/Alluring_Decors/Alluring_Decors-ejb/AdministratorFacade!vn.ac.c0910g.assignment.Entity.AdministratorFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public List<Administrator> getAllAdmin(){
        return this.administratorFacade.findAll();
    }

    public void addAdmin(Administrator admin){
        administratorFacade.create(admin);
    }

    public void updateAdmin(Administrator admin){
        administratorFacade.edit(admin);
    }

    public void deleteAdmin(Administrator admin){
        administratorFacade.remove(admin);
    }

    public Administrator findAdminById(String Id){
        return administratorFacade.find(Id);
    }

    public boolean checkLogin(String name, String pass){
        boolean b= false;
        if(administratorFacade.getUserByUsername(name, pass) != null){
            b = true;
        }else{
            b = false;
        }
        return b;
    }
}
